package com.example.library.util;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.example.library.DatabaseHelper;
import com.example.library.User;

import java.util.ArrayList;
import java.util.List;

public class UserQueryHelper {
    public static List<User> getAllUsers(Context context) {
        List<User> userList = new ArrayList<>();
        DatabaseHelper dbHelper = new DatabaseHelper(context);
        SQLiteDatabase db = dbHelper.getReadableDatabase();
        Cursor cursor = db.query("user", null, null, null, null, null, null);
        while (cursor.moveToNext()) {
            User user = new User();
            user.setId(cursor.getInt(cursor.getColumnIndex("id")));
            user.setName(cursor.getString(cursor.getColumnIndex("name")));
            user.setStudentId(cursor.getString(cursor.getColumnIndex("studentId")));
            user.setPassword(cursor.getString(cursor.getColumnIndex("password")));
            user.setContact(cursor.getString(cursor.getColumnIndex("contact")));
            user.setUserType(cursor.getString(cursor.getColumnIndex("userType")));
            user.setCreditScore(cursor.getInt(cursor.getColumnIndex("creditScore")));
            user.setStatus(cursor.getInt(cursor.getColumnIndex("status")));
            // 可补充更多字段
            userList.add(user);
        }
        cursor.close();
        db.close();
        return userList;
    }
} 